package com.smsc.headend.task.engine.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.smsc.headend.common.utils.R;
import com.smsc.headend.module.asset.entity.Meter;
import com.smsc.headend.module.data.dto.AnsiDataDTO;
import com.smsc.headend.module.data.dto.DataItemDTO;
import com.smsc.headend.module.data.dto.FtpCollectionDTO;
import com.smsc.headend.module.data.dto.LpDdsDTO;
import com.smsc.headend.module.data.dto.LpQueryDTO;
import com.smsc.headend.module.data.entity.RdMeterReadsLp;
import com.smsc.headend.module.data.enums.CollectionSource;
import com.smsc.headend.module.protocol.cosem.bo.CosemData;
import com.smsc.headend.module.task.dto.TaskReadData;
import com.smsc.headend.task.engine.exception.UDISTaskHandlerException;
import com.smsc.headend.task.engine.po.ScheduleReadingDataBo;
import com.smsc.headend.task.engine.po.ScheduleReadingPageBo;

import java.util.List;
import java.util.concurrent.ExecutionException;

public interface DataProcessService extends IService<RdMeterReadsLp> {


    /**
     * profile data persistent to DB
     *
     * @param result
     * @param collectionSource
     * @return
     */
    int saveTaskReadData(TaskReadData result, CollectionSource collectionSource);

    /**
     * handle ftp collection data
     *
     * @param result
     */
    void saveDLMSGatewayFtpCollectionData(FtpCollectionDTO result);

    /**
     * get ProfilesStatus Seq
     *
     * @param dataItemCosemList
     * @return
     */
    int getProfilesStatusSeq(List<DataItemDTO> dataItemCosemList);

    /**
     * get clock seq
     *
     * @param dataItemCosemList
     * @return
     */
    int getClockIndexInConfigDataItem(List<DataItemDTO> dataItemCosemList);

    List<RdMeterReadsLp> getRdMeterReadLpList(CosemData cosemData, Long lpTemplateId, Long lpDataItemId, List<DataItemDTO> dataItemCosemList, Meter meter, CollectionSource isODR) throws UDISTaskHandlerException;

    List<RdMeterReadsLp> getAnsiRdMeterReadLpList(List<AnsiDataDTO> ansiDataList, Long lpTemplateId, Long lpDataItemId, List<DataItemDTO> dataItemAnsiList, Meter meter, CollectionSource isODR) throws UDISTaskHandlerException;

    Boolean saveLoadProfileRecord(List<RdMeterReadsLp> readsLps) throws ExecutionException, InterruptedException;

    List<DataItemDTO> getLoadProfileCaptureObjects(Long lpTemplateId, Long lpDataItemId, Long meterId);

    /**
     * create task for Exporting load-profile from database
     *
     * @param lpDdsDto
     * @return
     */
    R createExportLoadProfileTask(LpDdsDTO lpDdsDto);

    void exportLoadProfileToDds(LpDdsDTO lpDdsDto);

    Integer saveShardedByMeterLp(List<RdMeterReadsLp> value, Long key);

    IPage<RdMeterReadsLp> pageRdMeterReadsLp(Long lpDataItemId, Long meterId, Long startTv, Long endTv, Integer page, Integer pageSize);

    IPage<RdMeterReadsLp> pageRdMeterReadsLpByRange(Long lpDataItemId, List<Long> meterIds, Long startTv, Long endTv, Integer page, Integer pageSize);

    ScheduleReadingPageBo pagePivotRdMeterReadsLp(Long lpDataItemId, Long meterId, Long startTv, Long endTv, Integer page, Integer pageSize, Long[] subDataItemIds);

    Integer countByTvs(Long lpDataItemId, List<Long> meterIds, Long startTv, Long endTv);

    ScheduleReadingDataBo lpDataPivotByOffsetAndLimit(Long[] meterIds, Long lpDataItemId, Long[] subDataItemIds, Long startTv, Long endTv, Integer offset, Integer limit);

    List<RdMeterReadsLp> getRdMeterReadLpList(Long meterId, Long lpDataItemId, Long subDataItemId, Long startTv, Long endTv);

    List<RdMeterReadsLp> getRdMeterReadLpList(List<Long> meterIds, Long subDataItemId, Long startTime, Long endTime);

    List<RdMeterReadsLp> queryElectricMeterData(LpQueryDTO lpQueryDTO);

    List<RdMeterReadsLp> queryElectricMeterDataByDaily(LpQueryDTO lpQueryDTO);
}
